<!--
Mark O'Meara
No Copying!
17th January 2012
-->

<html>
<head>
<title>Mark's FB app!</title>

<script type="text/javascript">

var appid = 193793277381130;
var pageurl = "http://www.mark-omeara.ie/fbapp/fb_friendsapp.html";

/*Function for display user's name*/
function dispName(user){
	var userName = document.getElementById('userName');
	//Print "Greetings, " followed by the user's Facebook name	
	var greetingText = document.createTextNode('Greetings, ' + user.name + '.');
   	userName.appendChild(greetingText);	
}


/*Function for initialising everything*/
function initFunc(){
	var notoken = "true";
	//Checks that there's a hash parameter
	if(location.hash){
		//Parses the parameters
		var hashes = location.hash.split('#')[1];
		var spl = hashes.split('&')[0].split('=');
		//If the hash parameter is the access_token
		if(spl[0] == "access_token"){
			/*spl now holds 'access_token' in first element, and the 
			access token value in the second element*/
			var tokenval = spl[1];
			notoken = "false";
			/*Gets the user info and sends it to the dispName function*/
			var script = document.createElement('script');
			script.src= "https://graph.facebook.com/me?access_token=" + tokenval + "&callback=dispName";
			document.body.appendChild(script);
		}
	}
	//If we don't have the access token, get it!
	if(notoken == "true"){
		window.location = "https://www.facebook.com/dialog/oauth?client_id=" + appid + "&redirect_uri=" + pageurl + "&response_type=token";
	}

}


</script>
</head>
<body>
<script type="text/javascript">
//Call the JavaScript function that does everything!
initFunc();
</script>
<!--This defines the paragraph where the greeting will be printed -->
<p id="userName"></p>
</body>
</html>
